package 搜狐发礼品;

import java.util.Scanner;

/**
 * Created by hest0 on 2017/4/17.
 */
public class Main不正确版 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = sc.nextInt();
            }
            int[] b = new int[a.length];
            for (int i = 0; i < a.length; i++) {
                b[i] = a[a.length - 1 - i];
            }
            System.out.println(Math.max(func(a, a.length), func(b, b.length)));
        }
        sc.close();
    }

    private static int func(int[] a, int n) {
        int r = 0;
        for (int i = 0; i < n; i++) {
            int j = i;
            while (j + 1 < n && a[j] < a[j + 1])
                j++;
            r += sum(j - i + 1);
            i = j;
        }
        return r;
    }

    public static int sum(int n) {
        int r = 0;
        for (int i = 1; i <= n; i++) {
            r += i;
        }
        return r;
    }

}
